package com.bwie.web.controller;

import com.bwie.pojo.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserController {

    //根据id查询用户
    @GetMapping("/{id}")
    public User listById(@PathVariable String id, HttpServletRequest request){

//        try {
//            Thread.sleep(5000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        int d=1/0;
        //获取远程调用的端口
        int port = request.getServerPort();
        //模拟从数据库查询出的数据
//        User user=new User(id,"Rose"+id);
        User user=new User(id,"来自"+port+"端口的Rose"+id);
        return user;
    }
}
